﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class ResponseButtonsController : ControllerBase
    {

        private readonly IResponseButtonAppService _app;
        public ResponseButtonsController(IResponseButtonAppService app)
        {
            this._app = app;
        }
        [HttpGet]
        [Route("buttons/{id:Guid}")]
        public ActionResult<ResponseButtonDto> Get([FromRoute] Guid id, [FromQuery]string include)
        {
            ResponseButtonDto responseButton = _app.Get(id, include); //include intent
            return Ok(responseButton);
        }

        [HttpGet]
        [Route("responses/{responseId:Guid}/buttons")]
        public ActionResult<IEnumerable<ResponseButtonDto>> GetList([FromRoute] Guid responseId, [FromQuery]string include)
        {
            IEnumerable<ResponseButtonDto> list = _app.GetList(responseId, include); //include intent
            return Ok(list);
        }

        [HttpPut]
        [Route("buttons/{id:Guid}")]
        public ActionResult<ResponseButtonDto> Put([FromRoute] Guid id, [FromBody] ResponseButtonUpdateDto dto)
        {
            ResponseButtonDto responseButton = _app.Update(id, dto);
            return Ok(responseButton);
        }

        [HttpPost]
        [Route("responses/{responseId:Guid}/buttons")]
        public ActionResult<ResponseButtonDto> Post([FromRoute] Guid responseId, [FromBody] ResponseButtonCreateDto dto)
        {
            ResponseButtonDto responseButton = _app.Add(responseId, dto);
            return CreatedAtAction(nameof(Get), new { id = responseButton.Id }, responseButton);
        }

        [HttpDelete]
        [Route("buttons/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }      
    }
}
